package com.zy.mobile.message.push.faio;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * 阻塞式IO 客户端
 * @author zhangyi
 *
 */
public class FAioTimeClient {
	
	public static void main(String[] args) {
		int port = 8080;
		if(args != null && args.length>0){
			try {
				port = Integer.valueOf(args[0]);
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
		Socket socket = null;
		BufferedReader in = null;
		PrintWriter out = null;
		
		try {
			socket = new Socket("127.0.0.1",port);
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			out = new PrintWriter(socket.getOutputStream(),true);
			out.println("query time order");
			System.out.println("send order to server succeed");
			String resp = in.readLine();
			System.out.println("now is : "+resp);
		} catch (Exception e) {
			// TODO: handle exception
			if(in != null){
				try {
					in.close();
				} catch (Exception e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}
			}
			if(out != null){
				out.close();
				out = null;			
			}
			if(socket != null){
				try {
					socket.close();
				} catch (Exception e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}
				socket = null;
			}
		}
	}
}
